<!--#include file="../nav/admin_top.php" -->
<div class="titleDiv">
	<div class="titleCaption">
		<span class="captionSpan">账户事务</span>
	</div>
</div>
<div class="menuBg">
	<a class="menuAdd" href="{url::build('admin_trans','add')}">添加账户事务</a>
  <div style="clear:both"></div>
</div>
<div style="margin:10px auto">
	搜索：
	<select class="textBox" id="transtype_id" onchange="fnSearchs()" >
		<option value="">所有类别</option>
		<?PHP
		foreach($transtype as $v){
			echo '<option value="'.$v['id'].'">'.$v['name'].'</option>';
		}
		?>
	</select>
	<select id="senddate" class="textBox"  onChange="fnSearchDate()" style="margin-right:5px;">
		<option value="0" selected="selected">所有日期</option>
		<option value="1">今天</option> 
		<option value="2">本周</option> 
		<option value="3">本月</option> 
		<option value="">自定义时间段</option> 
	</select>
	<span id="s_date_div" style="display:none;margin:5px auto;">
		从 <input type="text" class="textBoxDate" id="b_date" value=""   maxlength="10" />
		<input id="b_date_slt" class="btnicon_calendar" type="button">
		到
		<input type="text" class="textBoxDate" id="e_date" value=""   maxlength="10" />
		<input id="e_date_slt" class="btnicon_calendar" type="button">
	</span>	
	<input type="text" maxlength="12" id="keywords" class="searchs" /> 
	<input type="button"  onclick="fnSearchs()" value="查询"  />  	
</div> 
<div id="grids"></div> 
<script type="text/javascript">
var url_list = '/admin_trans/index';
var url_view = '/admin_trans/view';
var url_balance = '/admin_trans/userbalance';

$().ready(function(){
	showLoading();
	
	o2js.build('jquery_cluetip');
	o2js.build('o2grid');
	o2js.build('jscalendar');
	o2js.build('dates');
	fnSetSltDate('b_date','b_date_slt')
	fnSetSltDate('e_date','e_date_slt')
//	$('#b_date').val(getWeekFirst(new Date()).eformat('yyyy-MM-dd'));
//	$('#e_date').val(getWeekLast(new Date()).eformat('yyyy-MM-dd'));
	$('#b_date').val('');
	$('#e_date').val('');
	
	grids = new o2Grid({
		bind:'grids', 
		url:url_list,
		singleSelect:true,
		imgpath:'/misc/vendors/o2js/o2grid/image',
		cols:[
			{index:'id',mapping:'a.id', name:'序号', width:40,sortable:false, func:function(val,row_index,column_name,json,R){
				 return  '<span title="ID：'+json.id+'" >'+((R.page - 1)*R.rowNum + (row_index+1))+'</span>';
			}},
			{index:'username',mapping:'c.username', name:'会员'	, width:150,func:function(val,row_index,column_name,json,R){
			 
					var str =  '('+val+')'+json.user_name;
					return '<a  href="'+url_balance+'?id='+json.user_id+'" rel="'+url_balance+'?id='+json.user_id+'" class="balanceinfo" style="" >'+str+'</a>';
			 
			}},
			{index:'created',mapping:'a.created', name:'日期'	, width:150
			},
			{index:'transtype_name',mapping:'b.name', name:'类别', width:120
			},
			{index:'fee',mapping:'a.fee', name:'支出'	, width:100,align:'right',func:function(val,row_index,column_name,json,R){
				if(json.actions == '-'){
					return '<span style="color: ">'+json.fee+'</span>';
				}else{
					return ' ';
				}
			} },
			{index:'fee',mapping:'a.fee', name:'存入'	, width:100,align:'right',func:function(val,row_index,column_name,json,R){
				if(json.actions == '+'){
					return '<span style="color: ">'+json.fee+'</span>';
				}else{
					return ' ';
				}
			} },
			{index:'balance',mapping:'a.balance', name:'变动后余额'	, width:100,align:'right'
			},
			{index:'id',mapping:'a.id', name:'操作'	, width:100,align:'center',sortable:false,func:function(val,row_index,column_name,json,R){
					return  ' <a href="'+url_view+'?id='+json.id+'" style="color:blue" rel="'+url_view+'?id='+json.id+'" class="showinfo" >详情</a> ';
				}
			}
		],
		endfunc:function(obj){
			$('a.showinfo').cluetip({
				cluetipClass: 'jtip', 
				sticky: true,
				arrows: true, 
				dropShadow: false,
				closePosition: 'title',
				mouseOutClose: true,
				width:450
			}).each(function(){
				$(this).click(function(e){
					stopDefault(e);
				});
			});	
			$('a.balanceinfo').cluetip({
				cluetipClass: 'jtip',  
				sticky: true,
				arrows: true,
				closePosition: 'title',
				mouseOutClose: true,
				width:240
			}).each(function(){
				$(this).click(function(e){
					stopDefault(e);
				});
			});
		}
	});
	fnSearchs();	 
	$('#keywords').keypress(function(e){
		if(e.keyCode==13||e.keyCode==10){
			fnSearchs();
		}
	}); 
	
});   
function fnSearchs(){
	grids.setBaseParams({
		keywords:encodeURIComponent($('#keywords').val()),
		transtype_id:$('#transtype_id').val(),
		b_date:$('#b_date').val(),
		e_date:$('#e_date').val()
	}); 
	grids.load(1); 
}
/* 预定义日期 */
function fnSearchDate(){
	$('#s_date_div').hide();
	var date = new Date();
	switch($('#senddate').val()){
		case "0"://  
			$('#b_date').val('');
			$('#e_date').val('');
			break;
		case "1"://  
			$('#b_date').val(today());
			$('#e_date').val(today());
			break;
		case "2":// 
			var b = getWeekFirst(date).eformat('yyyy-MM-dd');
			var e = getWeekLast(date).eformat('yyyy-MM-dd'); 
			$('#b_date').val(b);
			$('#e_date').val(e);
			break;
		case "3"://本月
			var b = getMonthFirst(date).eformat('yyyy-MM-dd');
			var e = getMonthLast(date).eformat('yyyy-MM-dd'); 
			$('#b_date').val(b);
			$('#e_date').val(e);
			break;
		default:
			$('#s_date_div').show();
			break;
	}
	fnSearchs();
}
</script>
<!--#include file="../nav/admin_bottom.php" -->